﻿using Dx.DDD.Domain;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dx.DDD.Repositories
{
    public class UnitOfWork<T>: IUnitOfWork where T :  DbContext
    {
        public DbContext DbContext { get; set; }
        public UnitOfWork(T dbContext)
        {
            DbContext = dbContext;
        }

        public async Task SaveChangeAsync() 
        {
            await DbContext.SaveChangesAsync();
        }
    }
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
    public class UnitOfWorkAttribute : Attribute 
    {
        public UnitOfWorkAttribute(string? name) 
        {
            ConnectionString = name;
        }
        public string? ConnectionString { get; set; }
    }
}
